#include "OP_SelectAll.h"

using namespace std;
using namespace CICore;
using namespace CIGeom;
using namespace CIView;

///<************************************************************************************************************>
///<************************************* region CONSTANTS DEFINITION ******************************************>
///<************************************************************************************************************>

/***************************************************************************************************************
************************************** endregion CONSTANTS DEFINITION ******************************************
****************************************************************************************************************/












/// <summary> 
/// Constructor 
/// </summary>
/// <param name="v"> A reference to the vector that contains the four 3D views pointers </param>
CIOps::OP_SelectAll::OP_SelectAll (vector<CIView::View*>& v)
: Operation (v) {
}

/// <summary> 
/// Destructor 
/// </summary>
CIOps::OP_SelectAll::~OP_SelectAll() {}




///<************************************************************************************************************>
///<**************************************** region Utility Methods ********************************************>
///<************************************************************************************************************>

/// <summary> 
/// Method called to execute directly the operation 
/// </summary>
/// <returns> The operation status </returns>
int CIOps::OP_SelectAll::Exec() {

    if (scene.GetGeometries().empty()) {
        status = ZOMBIE;
        return status; 
    }

    SaveOldSelection();                             //Saves the old selection status

    switch (scene.GetSelectionMode()) {             //According to the current selection mode
        case Geometry::VERTICES_SELECTION:
            scene.SelectAllVertices();              //selects all vertices
            break;

        
        case Geometry::FACES_SELECTION:
            scene.SelectAllFaces();                 //selects all faces
            break;
    }

    SaveNewSelection();                             //Saves the new selection status
    
    views[0]->SetPrimitivesSelected (true);

    status = COMPLETED;

    RestoreFeedbackPosition();                      //Restores feedback position

    UpdateViews();                                  //Updates the 3D views

    return status;        
}

/// <summary> 
/// Method called to undo the operation 
/// </summary>
void CIOps::OP_SelectAll::Undo() {
    status = UNDO;

    RestoreOldSelection();      //Restore old selection status
    UpdateViews();              //Updates the 3D views
}

/// <summary> 
/// Method called to redo the operation 
/// </summary>
void CIOps::OP_SelectAll::Redo() {
    status = COMPLETED;

    RestoreNewSelection();      //Restore the new selectio status
    UpdateViews();              //Updates the 3D views
}

/// <summary> 
/// Mouse Pressed event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse press event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Pressed event </param>
void CIOps::OP_SelectAll::MousePressEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Mouse Released event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse release event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Released event </param>
void CIOps::OP_SelectAll::MouseReleaseEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Mouse Moved event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse move event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Mouse Moved event </param>
void CIOps::OP_SelectAll::MouseMoveEvent (CIView::View* view, QMouseEvent* e) {
}

/// <summary> 
/// Wheel event handler, called whenever the operation 
/// is in execution and a 3D view intercepts a mouse wheel event
/// </summary>
/// <param name="view"> The view that has thrown the event </param>
/// <param name="e"> Wheel event </param>
void CIOps::OP_SelectAll::WheelEvent (CIView::View* view, QWheelEvent* e) {
}
/***************************************************************************************************************
***************************************** endregion Utility Methods ********************************************
****************************************************************************************************************/
